/*
* PROJECT: Happy New Year
* VERSION: 1.0
* AUTHOR: Mattias Thell
* URL: http://www.mattiasthell.com
*
* */

#include "TargetRocket.hpp"
#include "Settings.hpp"
#include "World.hpp"

namespace hny 
{

	TargetRocket::TargetRocket(World* world, const hgeVector& position, const hgeVector& velocity, 
		int score, const hgeParticleSystemInfo& info, const hgeVector& target)
		
		:Rocket(world, position, velocity, score, info), 
		mTarget(target), mPrevDistance(1000000.0f)
	{
		SetCollidable(false);
	}

	TargetRocket::~TargetRocket()
	{
	}

	void TargetRocket::Update(float dt) 
	{

		if(!IsDying()) {
			hgeVector pos = GetPosition();
			float dist = hgeVector(pos - mTarget).Length();
			
			
			if(mPrevDistance < dist ) {
				StartDying();
				Rocket::GetWorld()->SpawnExplosion(pos);
			}

			mPrevDistance = dist;
		}
		Rocket::Update(dt);
	}
}